package com.lagou.springBootRocketmq.listener;

import com.lagou.springBootRocketmq.entity.Order;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import static com.lagou.springBootRocketmq.cons.Constant.*;

@Component
@RocketMQMessageListener(topic = ORDER_TIPIC,
        consumerGroup = ORDER_CONSUMER_GROUP,
        consumeMode = ConsumeMode.CONCURRENTLY,
        messageModel = MessageModel.CLUSTERING,
        secretKey = "*")
public class RocketMQOrderListener implements RocketMQListener<Order> {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public void onMessage(Order order) {
        System.out.println("接收MQ消息-》保存订单 -》" + order);
        String goods_count = redisTemplate.opsForValue().get(GOODS_COUNT);
        System.out.println("接收MQ消息-》查询库存 -》" + goods_count);
    }

}
